package com.flyduck.controller;

import com.flyduck.common.lang.Result;
import com.flyduck.entity.SysUser;
import com.flyduck.mapper.SysUserMapper;
import com.flyduck.service.SysUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @program: vue-admin-java
 * @description:
 * @author: flyduck
 * @create: 2024-05-27 21:55
 **/
@RestController
public class TestController {

    @Autowired
    private SysUserMapper sysUserMapper;
    @Autowired
    private BCryptPasswordEncoder bCryptPasswordEncoder;

    @PreAuthorize("hasRole('admin')")
    @GetMapping("/test")
    public Result<List<SysUser>> test(){
        return Result.success(sysUserMapper.selectList(null));
    }

    @PreAuthorize("hasAuthority('sys:user:list')")
    @GetMapping("/test/pass")
    public Result<String> pass(){
        String password = bCryptPasswordEncoder.encode("111111");
        boolean matches = bCryptPasswordEncoder.matches("111111", password);
        System.out.println("匹配结果 = " + matches);
        return Result.success(password);
    }
}
